cmake_minimum_required(VERSION 3.20)
project(minizip)

set(TARGET ${PROJECT_NAME})

set(PUBLIC_HDR_DIR ${CMAKE_CURRENT_LIST_DIR}/include)
FILE(GLOB H_FILES ${PUBLIC_HDR_DIR}/*.h)
FILE(GLOB SRC ${CMAKE_CURRENT_LIST_DIR}/src/**)

add_library(${TARGET} ${SRC} ${H_FILES})

find_library(libz z)
target_link_libraries(${PROJECT_NAME} PRIVATE ${libz})

target_include_directories(${TARGET} PUBLIC
    $<BUILD_INTERFACE:${PUBLIC_HDR_DIR}> # 只有编译时有值, install时为空
    $<INSTALL_INTERFACE:include> # 只有install时有值
)

set_target_properties(${TARGET} PROPERTIES PUBLIC_HEADER "${H_FILES}")

install(TARGETS ${TARGET}
    EXPORT ${TARGET}
    RUNTIME DESTINATION bin  # 执行程序和dll文件输出
    ARCHIVE DESTINATION lib  # 静态库和windows动态库导出符号 .lib
    LIBRARY DESTINATION lib  # linux和mac的动态库 .so .dylib
    PUBLIC_HEADER DESTINATION include/${TARGET} # 头文件所在路径
)

install(EXPORT ${TARGET} FILE ${TARGET}Config.cmake DESTINATION cmake)
